$(init);

function init(){
	$("#schemeGrid").jqGrid(
  	{
		altRows:false,
        url : ctx+"/common/extQuery?sqlid=scheme",
  	    autowidth:true,
        rownumbers : true, // 可自动在表格前面添加序号
        height:(($(window.document).height())-150),
  	    datatype: "json",    
  		colNames : ['方案名称','生成模块','模块名','功能名','功能作者','操作'],
		colModel : [ 
			{name : "NAME",index : "NAME",width : 80,sortable:false},
			{name : "PACKAGE_NAME",index : "PACKAGE_NAME",width : 80,sortable:false},
			{name : "MODULE_NAME",index : "MODULE_NAME",width : 80,sortable:false},
			{name : "FUNCTION_NAME",index : "FUNCTION_NAME",width : 80,sortable:false},
			{name : "FUNCTION_AUTHOR",index : "FUNCTION_AUTHOR",width : 80,sortable:false},
            {name : "cz",index : "jsmc",width : 50,sortable:false,align:"center",title:false,formatter:function(value,options,row){
                    return "<span class='tdcz'>"+
                        "<a title='修改' class='small_btn change' href=javascript:openModifyScheme('"+row.ID+"');>修改</a>"+
                        "<a title='删除' class='small_btn del' href=javascript:deleteGenScheme('"+row.ID+"');>删除</a>"+
                        "</span>";
                }}
   		],
        prmNames:{
        	rows:"limit"
        },
		jsonReader :{
			root: "message.list",   
		    page: "message.pageNumber",   
		    total: "message.totalPage",
		    records:"message.totalRow"
		},
        loadtext:"<img src="+ctx+"'/static/images/loading.gif'>&nbsp;&nbsp;拼命加载中...",
  		rowNum : 50,
		rowList : [ 50, 100, 150 ],
		pager : "#schemePager",
  	    mtype: "POST",
		viewrecords : true,
		sortable:false
     });
     //初始化验证
     formValidate("schemeForm");
     //自适应屏幕
     $(window).resize(function(){
     	$("#schemeGrid").setGridWidth($(window).width()*0.99);
     });
}
	
//刷新角色信息
function refreshSCHEME(){
	var data = $("#searchForm").getFormJson();
	$("#schemeGrid").setGridParam({"postData":data}).trigger("reloadGrid");
}

//打开新增方案弹出框
function openAddScheme(){
    formReset("schemeForm");
    // renderJSLX($("#sjlx").val());
    openSCHEME("新增方案");
}

//打开修改方案弹出框
function openModifyScheme(id){
    formReset("schemeForm");
    var result = doService(ctx+"/genTable/genScheme/query_genScheme_one","id",id);
    console.log(result);
    if (result) {
        bindForm("schemeForm",result);
        openSCHEME("修改方案");
    }
}

//打开方案信息
function openSCHEME(title){
    qyOpen(title,630,"schemeContent");
}

//保存或修改方案
function saveSCHEME() {
    qyConfirm("确定执行保存操作吗？", function (value) {
        if (value) {
            if ($("#schemeForm").valid()) {
                var url = ctx + "/genTable/genScheme/saveSCHEME";
                /*if (!isNewBean) {
                	url = ctx + "/xtwh/scheme/updateSCHEME";
                }*/
                var result = doFormService(url, "schemeForm");
                if (result) {
                    qyAlert("保存成功！", function () {
                        qyClose();
                        refreshSCHEME();
                    });
                }
            }
        }
    });
}

//genScheme
function deleteGenScheme(id) {
    qyConfirm("确定删除该记录吗？",function(value){
        if(value){
            var result = doService(ctx+"/genTable/genScheme/delete","id",id);
            if(result){
                qyAlert("删除成功！",function(){
                    qyClose();
                    refreshSCHEME();
                });
            }
        }
    });
}